class Solution
{
public:
    bool isMonotonic(vector<int> &nums)
    {
        int state = 0;
        for (int i = 1; i < nums.size(); ++i)
        {
            if (nums[i] != nums[i - 1])
            {
                int thisState = nums[i] > nums[i - 1] ? 1 : -1;
                if (state == 0)
                {
                    state = thisState;
                }
                else if (state * thisState < 0)
                {
                    return false;
                }
            }
        }
        return true;
    }
};